home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 April
/
EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso
/
EARCD
/
comm
/
bbs
/
Hydra11s.lha
/
HBBS
/
Source
/
Doors_System
/
AddDIZToList
/
Main.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-10-31
|
7KB
|
290 lines
/*
AddDIZToList
============
Adds a .DIZ to a file list
Options
=======
N_ND->ActiveDoor->SystemOptions
-------------------------------
none
Door Options (Command Line)
---------------------------
2 <confnum> | "BAD" | "HOLD" | "SYSOP"
3 <diz_file>
4 <filename>
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_protos.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#ifdef __SASC
int CXBRK(void) { return(0); }
int _CXBRK(void) { return(0); }
void chkabort(void) {}
#endif
#include <HBBS/ANSI_Codes.h>
#include <HBBS/Defines.h>
#include <HBBS/types.h>
#include <HBBS/structures.h>
#include <HBBS/hbbscommon_protos.h>
#include <HBBS/hbbscommon_pragmas.h>
#include <HBBS/Hbbsnode_protos.h>
#include <HBBS/Hbbsnode_pragmas.h>
#include <HBBS/release.h>
char *versionstr="$VER: AddDIZToList "RELEASE_STR;
struct Library *HBBSCommonBase=NULL;
struct Library *HBBSNodeBase=NULL;
struct BBSGlobalData *BBSGlobal=NULL;
struct NodeData *N_ND=NULL;
int N_NodeNum=-1;
char outstr[1024]; // temp string for displaying text..
struct List *FileID=NULL;
UBYTE *filename=NULL;
static VOID cleanup(ULONG num)
{
if (HBBSNodeBase)
{
HBBS_CleanUpDoor();
CloseLibrary (HBBSNodeBase);
}
if (HBBSCommonBase)
{
HBBS_CleanUpCommon();
CloseLibrary (HBBSCommonBase);
}
if (num) printf("Door Error = %d\n",num);
exit(0);
}
static VOID init(char *name)
{
if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
{
cleanup(1);
}
if (!(HBBS_InitCommon()))
{
cleanup(2);
}
if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
{
cleanup(3);
}
if (!(HBBS_InitDoor(N_NodeNum,name)))
{
cleanup(4);
}
SetProgramName(name);
}
/*
File Format of List file (as of 03-JAN-1995)
--------------------------------------------
F FileName.EXT 99999999 DD-MMM-YYYY |-File_ID------45 chars---------------------|
T HH:MM:SS |-More ID-----------------------------------|
N Node XXX |-More ID-----------------------------------|
I |-More ID-----------------------------------|
U Uploader Name/Sent bY string
C Comments, Not Displayed By File Lister
C Programs Unless Specified by the sysop...
X Nuker Comments
*/
void AddDIZ(int argc,char *argv[])
{
BPTR FH=NULL,FL;
struct FileInfoBlock FB;
LONG count=0;
char c;
struct Node *node;
char datestr[LEN_DATESTR];
char timestr[LEN_TIMESTR];
strcpy(outstr,N_ND->NodeSettings.NodePlayPen);
strcat(outstr,argv[4]);
if (FL=Lock(outstr,ACCESS_READ))
{
if (Examine(FL,&FB))
{
if (FH=Open(filename,MODE_OLDFILE))
{
Seek(FH,-1,OFFSET_END);
Read(FH,&c,1);
if (c!='\n') Write(FH,"\n",1);
}
else
{
FH=Open(filename,MODE_NEWFILE);
}
if (FH)
{
for (node = FileID->lh_Head ; count<N_ND->MaxDIZLines && node->ln_Succ ; node =node->ln_Succ,count ++)
{
switch(count)
{
case 0:
HBBS_GetDate(datestr);
sprintf(outstr,"F %-12s %8ld %s %s",argv[4],FB.fib_Size,datestr,node->ln_Name);
break;
case 1:
HBBS_GetTime(timestr);
sprintf(outstr,"T %s %s",timestr,node->ln_Name);
break;
case 2:
sprintf(outstr,"N Node %3d %s",N_NodeNum,node->ln_Name);
break;
default: // 3 or more..
sprintf(outstr,"I %s",node->ln_Name);
break;
}
strcat(outstr,"\n");
Write(FH,outstr,strlen(outstr));
}
if (N_ND->User.CallData.SentBy[0]) // blank sentby ?
{
DOOR_WriteText(ANSI_RESET ANSI_FG_BLUE ANSI_BOLD "Adding Sentby string!\r\n");
sprintf(outstr,"U %s",N_ND->User.CallData.SentBy);
Write(FH,outstr,strlen(outstr));
}
Close(FH);
}
}
UnLock(FL);
}
}
void DoorMain(int argc,char *argv[])
{
LONG ConfNum,loop;
struct ConfData *Conf;
if (argc>=4)
{
if (FileID=HBBS_LoadFile(argv[3]))
{
if (HBBS_NodesInList(FileID))
{
if ((stricmp(argv[2],"HOLD")==0) || (stricmp(argv[2],"SYSOP")==0))
{
if (N_ND->CurrentConf)
{
filename=N_ND->CurrentConf->HoldFileList;
}
}
else
{
if (stricmp(argv[2],"BAD")==0)
{
if (N_ND->CurrentConf)
{
filename=N_ND->CurrentConf->BadFileList;
}
}
else
{
// first we find the conference number.
if (ConfNum=atoi(argv[2]))
{
if (ConfNum>=1 && ConfNum<=BBSGlobal->Conferences) // Valid Conference ?
{
// now we get the data structure that points to the conference data
Conf=(struct ConfData *)GetNode(BBSGlobal->ConfList,ConfNum-1);
if (Conf->FileList)
{
// then we get a the filename of the list we want to add our .DIZ to
// which is the last items in the linked list of file lists..
filename=HBBS_ListName(Conf->FileList,Conf->FileLists-1);
}
}
}
}
}
if (filename)
{
DOOR_WriteText(ANSI_RESET ANSI_FG_CYAN ANSI_BOLD "Adding Diz To: " ANSI_ITALIC);
DOOR_WriteText(filename);
DOOR_WriteText(ANSI_RESET "\r\n");
AddDIZ(argc,argv);
}
}
else
{
DOOR_WriteText("Empty File ID, not adding!\r\n");
}
FreeStrList(FileID);
}
}
else
{
strcpy(outstr,"Invalid Parameters for AddDIZtoList\n");
for (loop=0;loop<argc;loop++)
{
strcat(outstr,argv[loop]);
strcat(outstr," ");
}
DOOR_SysopText(outstr);
HBBS_AddToCallersLog(outstr);
}
}
int main(int argc,char *argv[])
{
if (sscanf(argv[1],"%d",&N_NodeNum)==0)
{
printf("Invalid/No Paramaters for door!\n");
exit (20);
}
init("AddDIZToList");
if (BBSGlobal=HBBS_GimmeBBS())
{
if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
{
DoorMain(argc,argv);
}
}
cleanup(0);
}